#include "header.h"
extern gem gemDB[100];
extern game world;
gem::gem()
{
  rarity = 0;
  type = force;
  name = "Empty";
  attackName = "";
  element = light;
  power = 1;
  maxDurability = 1;
  currentDurability = 0;
  element = light;
}

gem::gem(string nname, string nattackname, gemType ntype, int npower, int ndefense, int ndurability, gemElement nelement, int nrarity)
{
  name = nname;
  attackName = nattackname;
  type = ntype;
  power = npower;
  defense = ndefense;
  maxDurability = ndurability;
  currentDurability = ndurability;
  element = nelement;
  rarity = nrarity;
}

void gem::setGem(string nname, string nattackname, gemType ntype, int npower, int ndefense, int ndurability, gemElement nelement, int nrarity)
{
  name = nname;
  attackName = nattackname;
  type = ntype;
  power = npower;
  defense = ndefense;
  maxDurability = ndurability;
  currentDurability = ndurability;
  element = nelement;
  rarity = nrarity;
}

void gemCopy(gem source, gem &dest)
{
  dest.name = source.name;
  dest.attackName = source.attackName;
  dest.type = source.type;
  dest.power = source.power;
  dest.defense = source.defense;
  dest.maxDurability = source.maxDurability;
  dest.currentDurability = source.currentDurability;
  dest.element = source.element;
  dest.rarity = source.element;
}

void breakGem(gem &target)
{
  target.rarity = 0;
  target.type = force;
  target.name = "Empty";
  target.attackName = "";
  target.element = light;
  target.power = 1;
  target.maxDurability = 1;
  target.currentDurability = 0;
  target.element = light;
}

void gemDBInit()
{
  gemDB[0].setGem("Clear Crystal","Buster Spark", force, 100,75, 10, light, 20);
  gemDB[1].setGem("Bright Ruby","Fireball", magic, 300,30, 2, fire, 35);
  gemDB[2].setGem("Shining Emerald","Mind Bullet", psych, 125,100, 20, dark, 40);
  gemDB[3].setGem("Radiant Sapphire","Wave Crush", magic, 200, 80, 10, water, 30);
}


void arrangePlayerGems()
{
  gem buffer[20];
  int num=0;
  for (int n=0;n<20;n++)
  {
    if (world.player.inventory[n].name!="Empty")
    {
      gemCopy(world.player.inventory[n],buffer[num]);
      num++;
    }
  }
  for (int n=0;n<20;n++)
  {
    gemCopy(buffer[n],world.player.inventory[n]);
  }
}
